The present invention relates generally to data processing units with a shift function. More particularly it relates, to a data processing unit with a shift function in which the shift direction is determined by the sign of data for specifying a shift width.
Data processing units with a shift function are widely used. FIG. 2 shows a conventional data processing unit with a shift function which includes a pair of registers 21 and 22, an arithmetic and logic unit (ALU) 23, a flags register 24, a shift width register 25, a data register 26, and a shifter 27. The shift width data for specifying the number of positions in a shift width is fed to the registers 21 and 22 from the data bus. The ALU 23 outputs an absolute value of data from the registers 21 and 22 and feeds the flags register 24 with a sign opposite that of the data. The shift width data is fed to the shift width register 25 from the data bus. The data to be shifted is fed to the data register 26 from the data bus. The data to be shifted is the one to be shifted by the shifter 27. The shifter 27 moves the data from the data register 26 by the number of positions in a shift width to the left or to the right.
In operation, the conventional data processing unit performs a shift operation in two steps. In the first step, the ALU 23 generates an absolute value of shift width data. That is, the shift width data (X) is subtracted from 0 to provide data (Y) with a sign opposite that of the difference. If X is positive, X is output on the data bus, while if Y is positive, Y is output on the data bus. At the same time, the sign of Y is set in the flags register 24. In the second step, the absolute value of the shift width data is stored in the shift width register 25. That is, if X is positive, X is stored, while if X is negative, Y is stored. The data to be shifted is stored in the data register 26. The data to be shifted 28 from the data register 26, a shift width control signal 29 from the shift width register 25, and a shift direction control signal 30 from the flags register 24 are all fed to the shifter 27, where the data to be shifted is moved by a predetermined number of bits to the left or to the right. Thus, the conventional data processing unit requires the two steps to drive the ALU and the shifter to perform a shift operation in which the shift direction is determined by a sign of data for specifying a shift width.